gila_all <- read_csv("data_gmocc-all-nv.csv")

gila_tracks <- filter(gila_all, det_type_strict != "v")

gila_vis <- filter(gila_all, det_type_strict != "s")
ggplot(gila_all, aes(rock_ind, det_strict)) +
  geom_point(size=3) +
  geom_smooth(method="lm",
              fullrange = TRUE) +
  labs(title="Gila monster detections - all data") +
  ylab ("Probability of Detection") +
  xlab ("'Sandiness Index'")
## `geom_smooth()` using formula = 'y ~ x'

ggplot(gila_all, aes(rock_ind, det_strict)) +
  geom_point(size=3) +
  geom_smooth(method="glm",
              fullrange = TRUE,
              method.args=list(family="binomial"(link="logit"))) +
  labs(title="Gila monster detections - all data") +
  ylab ("Probability of Detection") +
  xlab ("'Sandiness Index'")
## `geom_smooth()` using formula = 'y ~ x'

ggplot(gila_all, aes(rock_ind, det_strict)) +
  geom_point(size=2, position=position_jitter(width=0.1, height=0.15)) +
  geom_smooth(method="glm",
              fullrange = TRUE, #force fit line past limits of data
              method.args=list(family="binomial"(link="logit"))) +
  labs(title="Gila monster detections - all data") +
  ylab ("Probability of Detection") +
  xlab ("Sandiness Index")
## `geom_smooth()` using formula = 'y ~ x'

model_gila_all <- glm(det_strict ~ rock_ind, data=gila_all, family=binomial)
model_gila_all
## 
## Call:  glm(formula = det_strict ~ rock_ind, family = binomial, data = gila_all)
## 
## Coefficients:
## (Intercept)     rock_ind  
##     -6.7959       0.7527  
## 
## Degrees of Freedom: 1476 Total (i.e. Null);  1475 Residual
## Null Deviance:       381.8 
## Residual Deviance: 334.9     AIC: 338.9
newdata <- data.frame(rock_ind = seq(0, 7, length.out = 100))
newdata$logit_fit <- predict(model_gila_all, newdata = newdata, type = "link")

gila_all$det_adj <- (gila_all$det_strict + 0.5) / 2
gila_all$logit_obs <- log(gila_all$det_adj / (1 - gila_all$det_adj))
ggplot() +
  geom_point(data = gila_all, aes(x = rock_ind, y = logit_obs),
             color = "black", size = 2, alpha = 0.8) +
  geom_line(data = newdata, aes(x = rock_ind, y = logit_fit),
            color = "blue", linewidth = 1.2) +
  labs(
    title = "Gila monster detections - all data - Logit Scale")  +
  ylab ("Probability of Detection") +
  xlab ("Sandiness Index")

x <- predict(model_gila_all)
y <- resid(model_gila_all)
binnedplot(x, y)

coef(model_gila_all)
## (Intercept)    rock_ind 
##  -6.7958927   0.7526968
confint(model_gila_all)
## Waiting for profiling to be done...
##                  2.5 %    97.5 %
## (Intercept) -8.2138570 -5.593209
## rock_ind     0.5145914  1.017941
summary(model_gila_all)
## 
## Call:
## glm(formula = det_strict ~ rock_ind, family = binomial, data = gila_all)
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  -6.7959     0.6662 -10.201  < 2e-16 ***
## rock_ind      0.7527     0.1280   5.882 4.05e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 381.84  on 1476  degrees of freedom
## Residual deviance: 334.91  on 1475  degrees of freedom
## AIC: 338.91
## 
## Number of Fisher Scoring iterations: 7

1.384/4=0.346*100= 34.6%




ggplot(gila_tracks, aes(rock_ind, det_strict)) +
  geom_point(size=2, position=position_jitter(width=0.1, height=0.15)) +
  geom_smooth(method="glm",
              fullrange = TRUE, #force fit line past limits of data
              method.args=list(family="binomial"(link="logit"))) +
  labs(title="Gila monster detections - visual and tracks") +
  ylab ("Probability of Detection") +
  xlab ("Sandiness Index")
## `geom_smooth()` using formula = 'y ~ x'

model_gila_all <- glm(det_strict ~ rock_ind, data=gila_tracks, family=binomial)
model_gila_all
## 
## Call:  glm(formula = det_strict ~ rock_ind, family = binomial, data = gila_tracks)
## 
## Coefficients:
## (Intercept)     rock_ind  
##     -10.573        1.384  
## 
## Degrees of Freedom: 1464 Total (i.e. Null);  1463 Residual
## Null Deviance:       292.7 
## Residual Deviance: 219.1     AIC: 223.1
x <- predict(model_gila_all)
y <- resid(model_gila_all)
binnedplot(x, y)

coef(model_gila_all)
## (Intercept)    rock_ind 
##   -10.57333     1.38420
confint(model_gila_all)
## Waiting for profiling to be done...
##                   2.5 %    97.5 %
## (Intercept) -13.2989936 -8.328649
## rock_ind      0.9853142  1.848857
summary(model_gila_all)
## 
## Call:
## glm(formula = det_strict ~ rock_ind, family = binomial, data = gila_tracks)
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -10.5733     1.2652  -8.357   <2e-16 ***
## rock_ind      1.3842     0.2197   6.299    3e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 292.69  on 1464  degrees of freedom
## Residual deviance: 219.11  on 1463  degrees of freedom
## AIC: 223.11
## 
## Number of Fisher Scoring iterations: 8